// полный перебор без отсечений - решение на 50 баллов

const
  NMAX = 50;
  WMAX = 1000;
  INF = 1000000;

var
  n, i: longint;
  w: array[1 .. NMAX] of longint;
  fullWeight: longint;
  d: array[0..NMAX] of longint;
  s: array[0..2] of longint;
  s2opt: longint;

begin
  read(n);
  fullWeight := 0;
  for i := 1 to n do
  begin
    read(w[i]);
    fullWeight := fullWeight + w[i];
  end;

  s[0] := 0; s[1] := 0; s[2] := 0;
  for i := 1 to n do begin
    d[i] := 0;
    s[0] := s[0] + w[i];
  end;
  d[0] := 0;

  s2opt := INF;

  while d[0] = 0 do begin
    i := n;
    while d[i] = 2 do begin
      d[i] := 0;
      s[2] := s[2] - w[i];
      s[0] := s[0] + w[i];
      dec(i);
    end;
    s[d[i]] := s[d[i]] - w[i];
    inc(d[i]);
    s[d[i]] := s[d[i]] + w[i];
    if s[0] = s[1] then
      if s[2] < s2opt then
        s2opt := s[2];    
  end;
  writeln(s2opt);
end.
